package com.example.wechat;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;
import java.util.Map;

public class MyAdapterSub extends BaseAdapter {
    private List<Map<String, Object>> datas;
    private UserInfoFragment mContext;
    public  MyAdapterSub(List<Map<String,Object>> datas, UserInfoFragment mContext){
        this.datas = datas;
        this.mContext=mContext;
    }

    @Override
    public int getCount() {

        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if(convertView ==null){
            convertView= LayoutInflater.from(mContext.getActivity()).inflate(R.layout.listset_item,null);
            holder =new ViewHolder();
            holder.mImageView =(ImageView) convertView.findViewById(R.id.arrowImageView);
            holder.mTextView=(TextView) convertView.findViewById(R.id.textView);
            holder.mTextView.setOnClickListener(new View.OnClickListener(){
                @Override
                public  void onClick(View view){
                    Toast.makeText(mContext.getContext(),"你点了我啊哈哈哈",1).show();
                }
            });
            convertView.setTag(holder);

        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        holder.mImageView.setImageResource((Integer) datas.get(position).get("img"));
        holder.mTextView.setText(datas.get(position).get("title").toString());


        return convertView;
    }
    static class ViewHolder{
        ImageView mImageView;
        TextView mTextView;


    }
}
